package com.yuxl.centent.document.controller;

import com.yuxl.centent.document.entity.ContentDocument;
import com.yuxl.centent.document.service.ContentDocumentService;
import com.yuxl.common.core.annotation.Anonymous;
import com.yuxl.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * @Author : yuxl
 * @create 2025/9/8 下午7:59
 */
@Tag(name = "内容:文档")
@RequestMapping("/content/document")
@RestController
public class ContentDocumentController {

    @Resource
    private ContentDocumentService contentDocumentService;

    @Operation(summary = "创建文档")
    @PostMapping
    public Mono<R<ContentDocument>> add(@RequestBody ContentDocument entity) {
        return contentDocumentService.add(entity)
                .map(R::ok);
    }

    @Operation(summary = "根据ID查询文档")
    @GetMapping("/{id}")
    @Anonymous
    public Mono<R<ContentDocument>> getById(@PathVariable Long id) {
        return contentDocumentService.findById(id)
                .map(R::ok);
    }

    @Operation(summary = "更新文档")
    @PutMapping
    public Mono<R<ContentDocument>> updateById(@RequestBody ContentDocument entity) {
        return contentDocumentService.updateById(entity)
                .map(R::ok);
    }

    @Operation(summary = "删除文档")
    @DeleteMapping("/{id}")
    public Mono<R<Long>> deleteById(@PathVariable Long id) {
        return contentDocumentService.deleteById(id)
                .map(R::ok);
    }

    @Operation(summary = "批量删除文档")
    @DeleteMapping
    public Mono<R<Long>> deleteByIds(@RequestBody List<Long> ids) {
        return contentDocumentService.deleteByIds(ids)
                .map(R::ok);
    }

    @Operation(summary = "条件查询文档列表")
    @PostMapping("/list")
    @Anonymous
    public Mono<R<List<ContentDocument>>> list(@RequestBody ContentDocument entity) {
        return contentDocumentService.list(entity)
                .collectList()
                .map(R::ok);
    }

    @Operation(summary = "统计文档数量")
    @PostMapping("/count")
    public Mono<R<Integer>> count(@RequestBody ContentDocument entity) {
        return contentDocumentService.count(entity).map(R::ok);
    }

    @Operation(summary = "获取所有的path")
    @GetMapping("/pathAll")
    @Anonymous
    public Mono<R<List<ContentDocument>>> pathAll() {
        return contentDocumentService.pathAll().collectList().map(R::ok);
    }

    @Operation(summary = "分页条件查询文档")
    @PostMapping("/page/{page}/{size}")
    @Anonymous
    public Mono<R<List<ContentDocument>>> page(
            @RequestBody ContentDocument entity,
            @PathVariable int page,
            @PathVariable int size
    ) {
        return contentDocumentService.page(entity, page, size)
                .collectList()
                .map(R::ok);
    }
}
